#include<bits/stdc++.h>
using namespace std;
const int N=100006;
int n=0,m=0,V=0,L=0,ans[N],m1[N],dis[N],v0[N],a[N],s[N];
int main()//zhi xie a=0 de qing kuang
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    memset(ans,0,sizeof(ans));
    memset(m1,0,sizeof(m1));
    int t=0;cin>>t;
    for(int p=1;p<=t;p++)
    {
        cin>>n>>m>>L>>V;
        m1[p]=m;

        for(int i=1;i<=n;i++)
        {
            int dis1,v01,a1;
            cin>>dis1>>v01>>a1;
            dis[i]=dis1;
            v0[i]=v01;
            a[i]=a1;

        }
        for(int i=1;i<=m;i++)
        {
            int s1;
            cin>>s1;
            s[i]=s1;
        }
        for(int i=1;i<=n;i++)
        {
            if(v0[i]>V&&a[i]>=0&&dis[i]<=s[m])
            {
                ans[p]++;
                continue;
            }
            if(v0[i]<=V&&a[i]<=0)
            {
                continue;
            }
        }
    }
    for(int i=1;i<=t;i++)
    {
        if(ans[i]==0)cout<<0<<" "<<m1[i]<<endl;
        else cout<<ans[i]<<" "<<m1[i]-1<<endl;
    }
    return 0;
}
